package cn.z2huo.knowledge.designpattern.simplefactory.example2;

/**
 * 返利收费
 */
class CashReturn extends Cash {

    /**
     * 返利值
     */
    private double moneyReturn = 0;

    /**
     * 返利条件
     */
    private double moneyCondition = 0;

    public CashReturn(double moneyReturn, double moneyCondition) {
        this.moneyReturn = moneyReturn;
        this.moneyCondition = moneyCondition;
    }

    /**
     * 收取现金，返利
     * @param money 原价
     * @return 返利后的金额
     */
    @Override
    double acceptCash(double money) {
        double result = money;
        // 如果收费金额大于返利条件，则需要减去返利值
        if (money >= moneyCondition) {
            result = money - Math.floor(money / moneyCondition) * moneyReturn;
        }
        return result;
    }
}
